﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using PraiseSystem.Domain.Entities;
using PraiseSystem.Domain.Abstract;
using System.Collections.Generic;
using PraiseSystem.WebUI.Controllers;
using System.Linq;
using PraiseSystem.WebUI.Models;

namespace PraiseSystem.UnitTests
{
    [TestClass]
    public class PageTest
    {
        [TestMethod]
        public void Can_Pagenate()
        {
            //arrange
            Mock<IPraiseRepository> mock = new Mock<IPraiseRepository>();
            mock.Setup(p => p.Praises).Returns(new List<Praise> {
                new Praise { PraiseID=1, OwnerID="P1" },
                new Praise { PraiseID=2, OwnerID="P2" },
                new Praise { PraiseID=3, OwnerID="P3" },
                new Praise { PraiseID=4, OwnerID="P4" },
                new Praise { PraiseID=5, OwnerID="P5" },
                new Praise { PraiseID=6, OwnerID="P6" },
                new Praise { PraiseID=7, OwnerID="P7" },
                new Praise { PraiseID=8, OwnerID="P8" }
                });

            //act
            PraiseController controller = new PraiseController(mock.Object);
            controller.PageSize = 3;
            PraiseListViewModel result = (PraiseListViewModel)controller.List(3).Model;

            //Assert
            Praise[] praises = result.Praises.ToArray();
            Assert.AreEqual(praises.Length, 2);
            Assert.AreEqual(praises[0].PraiseID, 2);
            Assert.AreEqual(praises[1].PraiseID, 1);
            Assert.AreEqual(praises[0].OwnerID, "P2");
            Assert.AreEqual(praises[1].OwnerID, "P1");
        }
    }
}
